from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()   # Firefox浏览器
driver.maximize_window()
driver.implicitly_wait(1000) # seconds 

# 打开网页
driver.get('http://stockmonitor.info:3000')
driver.get('http://stockmonitor.info:3000/d/fIOo8v0Gk/gu-piao-zhang-die-fu-fen-bu-zhi-fang-tu?viewPanel=1&orgId=1&refresh=5s')

js='window.open("http://stockmonitor.info:3000/d/KHE12IhMk/dang-qian-zhang-ting-ge-gu?viewPanel=1&orgId=1&from=1607995416973&to=1608016178138");'
driver.execute_script(js)

handles = driver.window_handles
driver.switch_to_window(handles[0])
driver.get_screenshot_as_file("./test1.png")

driver.switch_to_window(handles[1])
driver.get_screenshot_as_file("./test2.png") # 截取当前窗口，并指定截图图片的保存位置
